package main.java.cn.wolfcode.web.controller;

import cn.wolfcode.domain.Department;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IDepartmentService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/department")
public class DepartmentContorler {
    @Autowired
    private IDepartmentService departmentServie;
    @RequiredPermission(name = "部门页面",expression = "department:list")
    @RequestMapping("/list")
     public String list(Model model,QueryObject qo){
        PageInfo<Department> pageInfo = departmentServie.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "department/list";
     }
    @RequiredPermission(name = "部门删除",expression = "department:delete")
     @RequestMapping("/delete")
     public String delete(Long id) {
         if (id != null) {
             departmentServie.deleteByPrimaryKey(id);
         }
         return "redirect:/department/list";
     }
     @RequiredPermission(name = "部门新增/编辑",expression = "department:saveOrUpdate")
     @RequestMapping("/saveOrUpdate")
     public String saveOrUpdate(Department department,Long id) {
         if (id != null) {
            departmentServie.updateByPrimaryKey(department);
         }else {
             departmentServie.insert(department);
         }
         return "redirect:/department/list";
     }

}
